<template>
    <view class="searchBarCity">
        <view class="searchBar-main">
            <image class="icon-search" src="/static/icon/icon_search_bar_search.png"></image>
            <input
                class="input input-search"
                :placeholder="placeholderText"
                confirm-type="search"
                @confirm="searchFn"
                v-model="value"
                placeholder-class="placeholderSearchClass1" />

            <uni-icons
                class="btn-remove"
                @click="setEmpty"
                v-if="value"
                type="close"
                :customIcons="'icon-gray-4'"></uni-icons>
            <!-- #ifdef H5 -->
            <text class="btn-search" @click="searchFn">搜索</text>
            <!-- #endif -->
        </view>
    </view>
</template>

<script>
export default {
    props: {
        placeholderText: {
            type: String,
            default: "",
        },
    },
    data() {
        return {
            value: "",
            lbs: null,
            current: "",
        }
    },
    mounted() {},
    methods: {
        setEmpty() {
            this.value = ""
            this.searchFn()
        },
        searchFn() {
            //搜索
            let key = this.value
            if (key && key.length) {
                key = key.trim()
            } else {
                key = ""
            }
            this.$emit("searchFn", key)
        },
    },
}
</script>

<style lang="scss">
.searchBarCity {
    display: flex;
    flex-direction: row;
    padding: 0 $app-item-padding;
    align-items: center;
    background: #fff;
    height: 80rpx;
    border-radius: 100rpx;
}
.searchBar-main {
    display: flex;
    flex-direction: row;
    flex: 1;

    height: 72rpx;
    border-radius: 36rpx;
    align-items: center;
    padding: 0 20rpx;
}
.input-search {
    display: flex;
    flex: 1;
    height: 72rpx;
    padding: 0px 10rpx;
    font-size: 24rpx;
}
.btn-search {
    display: flex;
    height: 72rpx;
    line-height: 72rpx;
    padding-left: 20rpx;
    align-items: center;
    justify-content: center;
    font-size: 28rpx;
}
.searchBar-actions {
    display: flex;
    flex-direction: row;
    margin-right: -20rpx;
}
.btn-action-item {
    width: 88rpx;
    display: flex;
    align-items: center;
    justify-content: center;
}
.city {
    display: flex;
    flex-direction: row;
    align-items: center;
    border-right: solid 1rpx #dfe0e0;
    padding-right: 16rpx;
}
.city-name {
    width: 100rpx;
    margin: 0 6rpx;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 28rpx;
    text-align: center;
}
.icon-lbs {
    width: 28rpx;
    height: 28rpx;
}
.icon-search {
    width: 32rpx;
    height: 32rpx;
}
.btn-remove {
    padding: 10rpx;
}
</style>
